/****************************************************
 * 创建人：  tanglei
 * 创建时间: 2022/11/25/11:29
 * 项目名称：springboot-test
 * 文件名称: HelloWorldController.java
 * 文件描述: @Description:
 *
 * All rights Reserved, Designed By 投资交易团队
 * @Copyright:2016-2022
 *
 ********************************************************/
package com.springboot.controller;

import com.springboot.event.MyEvent;
import com.springboot.event.Task;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 包名称：  com.springboot.controller
 * 类名称：HelloWorldController
 * 类描述：
 * 创建人：  tanglei
 * 创建时间：2022/11/25 11:29
 */
@Slf4j
@RestController
public class HelloWorldController {

    @Autowired
    private ApplicationEventPublisher eventPublisher;

    @RequestMapping("/")
    public String home() {
        return "home";
    }

    @RequestMapping("/hello")
    public String index(String name) {
        return "Hello " + name + ", I'm SpringBoot!";
    }

    @GetMapping("/mockTest")
    public String mockTest() {
        log.info("this is mockTest");
        return "this is mockTest";
    }

    @GetMapping("/evnetTest")
    public String evnetTest() {
        Task task = new Task();
        task.setId(1L);
        task.setTaskName("测试任务");
        task.setTaskContext("任务内容");
        task.setFinish(false);
        MyEvent event = new MyEvent(task);
        log.info("开始发布任务");
        eventPublisher.publishEvent(event);
        log.info("发布任务完成");
        return "";
    }

}

